# -*- coding: utf-8 -*-

import xadmin
from xadmin import views
from user.models import UserProfile, Group
from mysite.tasks import celery_send_email
from mysite import settings


class BaseSetting(object):
    #添加主题功能
    enable_themes = True
    use_bootswatch = True


class GlobalSettings(object):
    # 全局配置，后台管理标题和页脚
    title = "博流智能开发者社区"
    site_title = "后台数据管理"
    site_footer = " 博流智能科技(南京)有限公司"
    # 菜单收缩
    # menu_style = "accordion"

   
class UserAdmin(object):
    list_display = ('username', 'name', 'email', 'company', 'group', 'phone', 'password', 'status', 'level', 'date')
    search_fields = ['username', 'company']
    list_filter = ['username', 'company']
    ordering = ('company',)
    
    def save_models(self):
        obj = self.new_obj
        obj.save()
        content = "http://dev.bouffalolab.com/\n登录名：" + obj.username + " 或 " + obj.email + "\n初始密码：123456"
        maillist = [obj.email]                              
        celery_send_email.delay(u'【博流智能开发者社区】账户开通', content, settings.EMAIL_HOST_USER, maillist)
        
        
class GroupAdmin(object):
    list_display = ('name', 'status')
    search_fields = ['name']
    list_filter = ['name']       
             
             
xadmin.site.register(views.BaseAdminView, BaseSetting)
xadmin.site.register(views.CommAdminView, GlobalSettings)
xadmin.site.register(UserProfile, UserAdmin)
xadmin.site.register(Group, GroupAdmin)

